package cs236369.hw5;

import java.util.*;

import ws.reg.RegistrationService;

/**
 * This is a VERY simple class for the registration web service being used in the 5th assignment of course cs236369,
 * IIT. It is responsible for managing the registration of Endpoints - a full and valid url. The registration is limited
 * to 100 entries.
 */
@SuppressWarnings({"javadoc"})
public class RegistrationServiceStub implements RegistrationService {
	
	private static final int			MAX_SIZE	= 1000;
	private static final String			MY_ENDPOINT	= "http://84.108.165.180:8081/SearchWS/services/SearchWSImpl?wsdl";
	private static Collection<String>	endpoints	= new HashSet<>();
	
	public RegistrationServiceStub() {
	}
	
	/**
	 * This method registers the url given in the registered endpoints list. It returns one of the following
	 * self-explanatory strings: Registration succeeded, Illegal Input, Already Registered, No place for you...
	 * 
	 * @param url The url of the endpoint to register
	 */
	@Override
	public String addEndpoint(String url) {
		if (url.equals(null)) {
			return ("Illegal Input");
		}
		if (endpoints.contains(url)) {
			return ("Already Registered");
		}
		if (endpoints.size() >= MAX_SIZE) {
			return ("No place for you...");
		}
		
		endpoints.add(url);
		return ("Registration succeeded");
	}
	
	/**
	 * This method removes the url given from the registered endpoints list It returns one of the following
	 * self-explanatory strings: Delete Succeeded, Delete Failed
	 * 
	 * @param url The url of the endpoint to remove
	 */
	@Override
	public String deleteEndpoint(String url) {
		if (url.equals(null) || !(endpoints.contains(url))) {
			return ("Delete Failed");
		}
		
		endpoints.remove(url);
		return ("Delete Succeeded");
		
	}
	
	/**
	 * This method returns an array of Strings with the current registered endpoints
	 * 
	 * @return The registered endpoints Strings array
	 */
	@Override
	public String[] getRegisteredEndpoints() {
		String[] strings = new String[endpoints.size()];
		return endpoints.toArray(strings);
	}
}
